//
//  MainViewController.swift
//  MQWeibo
//
//  Created by SYN on 15/11/11.
//  Copyright © 2015年 SYN. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {
    
    @IBOutlet weak var mainTabBar: MainTabBar!
    override func viewDidLoad() {
        super.viewDidLoad()
        //添加子视图
        addChildViewControllers()
        
        //直接给撰写按钮添加监听方法
        mainTabBar.composedButton.addTarget(self, action: "clickCompose", forControlEvents: UIControlEvents.TouchUpInside)
    }
    
    /**
        撰写按钮监听方法
    */
    func clickCompose(){
        print("\(__FUNCTION__)")
    }
    
    
    ///添加所有的子视图控制器
    private func addChildViewControllers() {
        //设置文字的渲染颜色
        tabBar.tintColor = UIColor.orangeColor()
        
        addChildViewController("Home", "首页", "tabbar_home")
        
        addChildViewController("Message", "消息", "tabbar_message_center")
        
        addChildViewController("Discover", "发现", "tabbar_discover")
        
        addChildViewController("Profile", "我", "tabbar_profile")
    }
    
    ///swift中允许函数重载,函数名相同,参数的个数及类型不同
    private func addChildViewController(sbName:String,_ title:String,_ imageName:String) {
        
        let sb = UIStoryboard(name:sbName, bundle: nil)
        
        let nav = sb.instantiateInitialViewController() as! UINavigationController
        
//        nav.title = title
        
        nav.topViewController?.title = title
        
        nav.tabBarItem.image = UIImage(named: imageName)
        
        nav.tabBarItem.selectedImage = UIImage(named: imageName + "_highlighted")
        
        addChildViewController(nav)
    }
    
}
